LDAP authentication, API key and some CLI improvements #250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The LDAP authentication works by:
Look up the user in the LDAP server
If the user exists try to authenticate (bind)
If it succeeds and the user doesn't exist in the database a new one is created (with ldap=1)
If the user does not exist try the supysonic database (with ldap=0)
Other things considered:
It requires the ldap3 module but if it's not installed it just throws a warning in the log.
To disable LDAP authentication just comment the ldap section in the config.
The mysql fields "password" and "salt" are now nullable because they are null if the user is from LDAP.
A new mysql field was added "ldap" with default 0.
It adds an icon to the user profile if they are a LDAP user.
Some features like changing email and password are disabled because it doesn't make sense to change them manually. Changing username is allowed.
Regarding the API key, I think its safer to use a key for API authentication since it is just sent encoded and not encrypted, so since I was modifying the code for LDAP authentication I also joined these changes because it would then be too confusing.
The API key authentication works by:
If require_api_key is enabled: try to login with the API key
If require_api_key is disabled: try API key first then password if it fails
It adds a form to the user profile to generate a new key or delete the existing one.
It adds new option group to the cli: "user api key" with commands: show, new and delete
A new mysql field was added "api_key" with default 0.
I also adapted the cli to the LDAP authentication and ended up making some improvements:
Added a new option group "user edit"
Moved "changepass" to "user edit password"
Moved "rename" to "user edit username"
Added a new option "user edit email"